<?php



namespace app\index\controller;


use app\common\library\RsaUtils;
use function GuzzleHttp\Promise\all;

class Api extends Base
{

    /**
     * 接口基本
     *
     *
     * @return mixed
     */
    public function index()
    {
        if ($this->request->isPost()) {
            if ($this->request->post('u/a')['uid'] == is_login()) {
                $this->result($this->logicApi->editApi($this->request->post('u/a')));
            } else {
                $this->result(0, '非法操作，请重试！');
            }
        }

        $this->apiCommon();
        return $this->fetch();
    }

    /**
     * 可用渠道
     *
     *
     * @return mixed
     */
    public function channel()
    {
        $channel = $this->logicPay->getCodeList(['status' => '1'], true, 'create_time desc', 10);
        $this->assign('list', $channel);
        return $this->fetch();
    }


    /**
     * API公共
     *
     *
     */
    public function apiCommon()
    {
        $this->assign('api', $this->logicApi->getApiInfo(['uid' => is_login()]));

        $this->assign('rsa', $this->logicConfig->getConfigInfo(['name' => 'rsa_public_key'], 'value'));
    }

    /**
     * 开发文档
     *
     *
     * @return mixed
     */
    public function document()
    {
        //获取商户详细信息
        return $this->fetch();
    }

    public function resetkey()
    {
        $this->result(1, '新的签名密钥生成成功，提交修改后生效。', md5(getRandChar(32)));
    }
}

